package org.fuys.etp.repo.po;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;

import java.io.Serializable;

/**
 * 动态线程池配置
 * @TableName etp_dynamic_config
 */
@TableName(value ="etp_dynamic_config")
@Data
public class EtpDynamicConfig implements Serializable {
    /**
     * 配置版本 主键自增 根据version来切换版本
     */
    @TableId(type = IdType.AUTO)
    private Integer dynamicVersion;

    /**
     * 最大核心线程数改变步长 为空时不限制
     */
    private Integer maxCoreThreadStep;

    /**
     * 最大最大线程数改变步长 为空时不限制
     */
    private Integer maxMaxThreadStep;

    /**
     * 最大队列大小改变步长 为空时不限制
     */
    private Integer maxQueueSizeStep;

    /**
     * 窗口内任务变化趋势 单位为比值 当任务预测增长此大小 如增长百分之20 则进行配置变化
     */
    private Double windowsChangeTrend;

    /**
     * PID算法KP参数
     */
    private Double pidKp;

    /**
     * PID算法KI参数
     */
    private Double pidKi;

    /**
     * PID算法KD参数
     */
    private Double pidKd;

    /**
     * PID期望目标 指代队列使用率
     */
    private Double pidTarget;

    /**
     * 基础配置
     */
    private Integer baseConfigVersion;

    /**
     * 负载等级
     */
    private Object loadLevel;

    /**
     * 滑动窗口大小
     */
    private Integer windowSize;

    /**
     * 滑动窗口启动阈值
     */
    private Integer windowMinSize;

    /**
     * 滑动窗口采用的移动平均加权算法的权重 采用,分割它们
     */
    private String windowWeights;

    @TableField(exist = false)
    private static final long serialVersionUID = 1L;

    @Override
    public boolean equals(Object that) {
        if (this == that) {
            return true;
        }
        if (that == null) {
            return false;
        }
        if (getClass() != that.getClass()) {
            return false;
        }
        EtpDynamicConfig other = (EtpDynamicConfig) that;
        return (this.getDynamicVersion() == null ? other.getDynamicVersion() == null : this.getDynamicVersion().equals(other.getDynamicVersion()))
            && (this.getMaxCoreThreadStep() == null ? other.getMaxCoreThreadStep() == null : this.getMaxCoreThreadStep().equals(other.getMaxCoreThreadStep()))
            && (this.getMaxMaxThreadStep() == null ? other.getMaxMaxThreadStep() == null : this.getMaxMaxThreadStep().equals(other.getMaxMaxThreadStep()))
            && (this.getMaxQueueSizeStep() == null ? other.getMaxQueueSizeStep() == null : this.getMaxQueueSizeStep().equals(other.getMaxQueueSizeStep()))
            && (this.getWindowsChangeTrend() == null ? other.getWindowsChangeTrend() == null : this.getWindowsChangeTrend().equals(other.getWindowsChangeTrend()))
            && (this.getPidKp() == null ? other.getPidKp() == null : this.getPidKp().equals(other.getPidKp()))
            && (this.getPidKi() == null ? other.getPidKi() == null : this.getPidKi().equals(other.getPidKi()))
            && (this.getPidKd() == null ? other.getPidKd() == null : this.getPidKd().equals(other.getPidKd()));
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((getDynamicVersion() == null) ? 0 : getDynamicVersion().hashCode());
        result = prime * result + ((getMaxCoreThreadStep() == null) ? 0 : getMaxCoreThreadStep().hashCode());
        result = prime * result + ((getMaxMaxThreadStep() == null) ? 0 : getMaxMaxThreadStep().hashCode());
        result = prime * result + ((getMaxQueueSizeStep() == null) ? 0 : getMaxQueueSizeStep().hashCode());
        result = prime * result + ((getWindowsChangeTrend() == null) ? 0 : getWindowsChangeTrend().hashCode());
        result = prime * result + ((getPidKp() == null) ? 0 : getPidKp().hashCode());
        result = prime * result + ((getPidKi() == null) ? 0 : getPidKi().hashCode());
        result = prime * result + ((getPidKd() == null) ? 0 : getPidKd().hashCode());
        return result;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(getClass().getSimpleName());
        sb.append(" [");
        sb.append("Hash = ").append(hashCode());
        sb.append(", dynamicVersion=").append(dynamicVersion);
        sb.append(", maxCoreThreadStep=").append(maxCoreThreadStep);
        sb.append(", maxMaxThreadStep=").append(maxMaxThreadStep);
        sb.append(", maxQueueSizeStep=").append(maxQueueSizeStep);
        sb.append(", windowsChangeTrend=").append(windowsChangeTrend);
        sb.append(", pidKp=").append(pidKp);
        sb.append(", pidKi=").append(pidKi);
        sb.append(", pidKd=").append(pidKd);
        sb.append(", serialVersionUID=").append(serialVersionUID);
        sb.append("]");
        return sb.toString();
    }
}